export class NotificationManager {
    static show(message, type = 'info', duration = 3000) {
        const icons = {
            success: 'bi-check-circle-fill',
            error: 'bi-exclamation-triangle-fill',
            warning: 'bi-exclamation-circle-fill',
            info: 'bi-info-circle-fill'
        };

        const colors = {
            success: 'alert-success',
            error: 'alert-danger',
            warning: 'alert-warning',
            info: 'alert-info'
        };

        const $notification = $(`
            <div class="alert ${colors[type]} alert-dismissible fade show position-fixed notification-toast" 
                 style="top: 20px; right: 20px; z-index: 9999; min-width: 300px; max-width: 400px;">
                <i class="${icons[type]} me-2"></i>
                <span>${message}</span>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        `);

        $notification.find('.btn-close').on('click', () => {
            $notification.remove();
        });

        // 如果已有通知，向下偏移
        const existingNotifications = $('.notification-toast');
        if (existingNotifications.length > 0) {
            const offset = existingNotifications.length * 80;
            $notification.css('top', `${20 + offset}px`);
        }

        $('body').append($notification);

        // 自动移除
        if (duration > 0) {
            setTimeout(() => {
                $notification.remove();
            }, duration);
        }

        return $notification;
    }

    static success(message, duration = 3000) {
        return this.show(message, 'success', duration);
    }

    static error(message, duration = 5000) {
        return this.show(message, 'error', duration);
    }

    static warning(message, duration = 4000) {
        return this.show(message, 'warning', duration);
    }

    static info(message, duration = 3000) {
        return this.show(message, 'info', duration);
    }
}